<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增党组织活动记录')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-activity-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动组织机构：</label>
                <div class="col-sm-8">
               		<select id="org" class="form-control select2-multiple" name="orgId">
						<option th:each="org:${orgs}" th:value="${org.orgId}"
							th:text="${org.orgName}"></option>
					</select>
                    <!-- <input name="orgId" class="form-control" type="text" maxlength="10" required> -->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动类型：</label>
                <div class="col-sm-8">
                    <select name="orgType" class="form-control m-b" th:with="type=${@dict.getType('act_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">活动主题：</label>
                <div class="col-sm-8">
                    <textarea name="actSubject" maxlength="100" class="form-control" required placeholder="请填写活动主题"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动日期：</label>
                <div class="col-sm-8">
                     <input name="actDate" class="form-control time-input" placeholder="请填写活动日期" type="text" maxlength="10" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动起止时间：</label>
                <div class="col-sm-8">
                    <input name="actDateRange" placeholder="格式为19:00:00-21:00:00" class="form-control" type="text" maxlength="20" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">活动地点：</label>
                <div class="col-sm-8">
                    <input name="actAddr" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">非正式党员是否可以参加：</label>
                <div class="col-sm-8">
                    <select name="partyOnly" class="form-control m-b" th:with="type=${@dict.getType('party_only')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/activity"
        $("#form-activity-add").validate({
            focusCleanup: true,
            rules:{
            	actDateRange:{
                    timeRange:true,
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-activity-add').serialize());
            }
        }

       
        
        $(function(){
        	$('#org').select2({
                placeholder: "请选择活动组织机构",
                allowClear: true
            });
        	
        	
        	 jQuery.validator.addMethod("timeRange", function (value, element){
 		        return this.optional(element) || isTimeRange(value);
 		    },"请正确输入时间区间");
        	 
        	 function isTimeRange(time) {
        		console.log(time);
        		var pattern = /[0-2]\d:[0-5]\d:[0-5]\d-[0-2]\d:[0-5]\d:[0-5]\d/;
        		if(pattern.test(time)){
        			// 时间格式符合的情况下，验证前者时间小于后者时间
        			var arr = time.split("-");
        			var begin = arr[0];
        			var end = arr[1];
        			var begin_arr = begin.split(":");
        			var begin_hour = begin_arr[0];
        			var begin_minute = begin_arr[1];
        			var begin_second = begin_arr[2];
        			
        			var end_arr = end.split(":");
        			var end_hour = end_arr[0];
        			var end_minute = end_arr[1];
        			var end_second = end_arr[2];
        			if(parseInt(begin_hour)<=parseInt(end_hour)){
        				if(parseInt(begin_hour)==parseInt(end_hour)){
        					// 小时相等的情况下才需要比较分钟
        					if(parseInt(begin_minute)<=parseInt(end_minute)){
        						if(parseInt(begin_minute)==parseInt(end_minute)){
        							// 分钟相等的情况下才需要比较秒
        							if(parseInt(begin_second)<parseInt(end_second)){
                						return true;
                					}else{
                						return false;// 秒验证失败
                					}
        						}else{
        							return true;
        						}
            				}else{
            					return false;// 分钟验证失败
            				}
        				}else{
        					return true;
        				}
        			}else{
						return false;// 小时验证失败        				
        			}
        		}else{
        			return false; // 时间格式已经不匹配
        		}
                
             }
        	
        });
    </script>
</body>
</html>